{% extends './layout.html' %} {% block title %} {{ title }} {% endblock %} {% block body %}
<div class="layout_head">
	<h2>添加小说</h2>
</div>
<div class="layout_cont">
	<form class="layui-form">
		<div class="layui-form-item">
			<label class="layui-form-label">小说名称</label>
			<div class="layui-input-block">
				<input type="text" name="bookname" lay-verify="required" autocomplete="off" placeholder="请输入小说名称" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">小说作者</label>
			<div class="layui-input-block">
				<input type="text" name="bookauthor" placeholder="请输入小说作者" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">小说类型</label>
			<div class="layui-input-inline">
				<select name="booktype">
					<option value=""></option>
					<option value="0">写作</option>
					<option value="1">阅读</option>
					<option value="2">游戏</option>
					<option value="3">音乐</option>
					<option value="4">旅行</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">小说封面</label>
			<div class="layui-input-inline">
				<button type="button" class="layui-btn" id="imgUpload"><i class="layui-icon">&#xe67c;</i> 上传图片</button>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">小说状态</label>
			<div class="layui-input-inline">
				<input type="checkbox" name="bookstatus" lay-skin="switch" lay-filter="switchStatus" lay-text="更新中|已完结">
			</div>
		</div>
		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">小说简介</label>
			<div class="layui-input-block">
				<textarea name="booknotice" placeholder="请输入小说简介" class="layui-textarea"></textarea>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">来源站点</label>
			<div class="layui-input-inline">
				<select name="sourcesite">
					<option value="0">写作</option>
					<option value="1">阅读</option>
					<option value="2">游戏</option>
					<option value="3">音乐</option>
					<option value="4">旅行</option>
				</select>
			</div>
			<label class="layui-form-label">链接地址</label>
			<div class="layui-input-block" style="margin-left: 420px;">
				<input type="text" name="capturehref" placeholder="请输入获取小说链接地址" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button type="submit" class="layui-btn" lay-submit="" lay-filter="add">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
</div>
{% endblock %}{% block scripts %}
<script type="text/javascript">
	layui.use(['form', 'upload'], function() {
		var form = layui.form;
		var upload = layui.upload;
		var bkStatus = 0;
		var bkimgSrc = null;
		upload.render({
			elem: '#imgUpload', //绑定元素
			url: '/upload/', //上传接口
			acceptMime: 'image/jpg, image/png, image/jpeg',
			field: 'bookimg',
			done: function(res) {
				//上传完毕回调
				bkimgSrc = res.data;
			},
			error: function() {
				//请求异常回调
			}
		});
		form.on('switch(switchStatus)', function(){
			bkStatus = this.checked ? 1 : 0;
		});
		//监听提交
		form.on('submit(add)', function(data) {
			data.field.bookimg = bkimgSrc;
			data.field.bookstatus = bkStatus;
			console.log(data.field);
			$.post('create', data.field, function(res) {
				if(res.code == 200){
					window.location.href = '/chapter/{{bookno}}'
				}
			})
			return false;
		});
	});
</script>
{% endblock %}